import Vue from 'vue'
import VueRouter from 'vue-router'
const index = () => import(/* webpackChunkName: "web" */ '../views/index')
// import index from '../views/index';
const home = () => import(/* webpackChunkName: "web" */ '../views/home')
// import home from '../views/home';
const help = () => import(/* webpackChunkName: "web" */ '../views/help')
// import help from "../views/help";
const activity = () => import(/* webpackChunkName: "web" */ '../views/activity')
// import activity from "../views/activity";
const job = () => import(/* webpackChunkName: "web" */ '../views/job')
// import job from "../views/job";
const oldstuff = () => import(/* webpackChunkName: "web" */ '../views/oldstuff')
// import oldstuff from "../views/oldstuff";
const news = () => import(/* webpackChunkName: "web" */ '../views/news')
// import news from "../views/news";
const search = () => import(/* webpackChunkName: "web" */ '../views/search')
// import search from "../views/search";
const feedback = () => import(/* webpackChunkName: "webkefu" */ '../views/kefu/feedback')
// import feedback from "../views/kefu/feedback";
const report = () => import(/* webpackChunkName: "webkefu" */ '../views/kefu/report')
// import report from "../views/kefu/report";
const appeal = () => import(/* webpackChunkName: "webkefu" */ '../views/kefu/appeal')
// import appeal from "../views/kefu/appeal";
const adminindex = () => import(/* webpackChunkName: "webAdmin" */ '../views/admin/adminindex')
// import adminindex from "../views/admin/adminindex";

const helpcontent = () => import(/* webpackChunkName: "webContent" */ '../views/content/helpcontent')
// import helpcontent from "../views/content/helpcontent";
const activitycontent = () => import(/* webpackChunkName: "webContent" */ '../views/content/activitycontent')
// import activitycontent from "../views/content/activitycontent";
const jobcontent = () => import(/* webpackChunkName: "webContent" */ '../views/content/jobcontent')
// import jobcontent from "../views/content/jobcontent";
const oldstuffcontent = () => import(/* webpackChunkName: "webContent" */ '../views/content/oldstuffcontent')
// import oldstuffcontent from "../views/content/oldstuffcontent";
const newscontent = () => import(/* webpackChunkName: "webContent" */ '../views/content/newscontent')
// import newscontent from "../views/content/newscontent";
const companycontent = () => import(/* webpackChunkName: "webContent" */ '../views/content/companycontent')
// import companycontent from "../views/content/companycontent";

const adminhome = () => import(/* webpackChunkName: "webAdmin" */ '../views/admin/adminhome')
// import adminhome from "../views/admin/adminhome";
const myself = () => import(/* webpackChunkName: "webAdmin" */ '../views/admin/myself')
// import myself from "../views/admin/myself";
const notice = () => import(/* webpackChunkName: "webAdmin" */ '../views/admin/notice')
// import notice from "../views/admin/notice";
const helplist = () => import(/* webpackChunkName: "webAdminHelp" */ '../views/admin/help/helplist')
// import helplist from "../views/admin/help/helplist";
const createhelp = () => import(/* webpackChunkName: "webAdminHelp" */ '../views/admin/help/createhelp')
// import createhelp from "../views/admin/help/createhelp";
const activitylist = () => import(/* webpackChunkName: "webAdminActivity" */ '../views/admin/activity/activitylist')
// import activitylist from "../views/admin/activity/activitylist";
const createactivity = () => import(/* webpackChunkName: "webAdminActivity" */ '../views/admin/activity/createactivity')
// import createactivity from "../views/admin/activity/createactivity";
const company = () => import(/* webpackChunkName: "webAdminJob" */ '../views/admin/job/company')
// import company from "../views/admin/job/company";
const oldstufflist = () => import(/* webpackChunkName: "webAdminOldStuff" */ '../views/admin/oldstuff/oldstufflist')
// import oldstufflist from "../views/admin/oldstuff/oldstufflist";
const createoldstuff = () => import(/* webpackChunkName: "webAdminOldStuff" */ '../views/admin/oldstuff/createoldstuff')
// import createoldstuff from "../views/admin/oldstuff/createoldstuff";
const newslist = () => import(/* webpackChunkName: "webAdminNews" */ '../views/admin/news/newslist')
// import newslist from "../views/admin/news/newslist";
const createnews = () => import(/* webpackChunkName: "webAdminNews" */ '../views/admin/news/createnews')
// import createnews from "../views/admin/news/createnews";

Vue.use(VueRouter)
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}

const routes = [
  {
    path: '/',
    component: index,
    meta: { ispublic: true },
    children: [
      { path: '', name: 'home', component: home, meta: { ispublic: true } },
      { path: 'help', name: 'help', component: help, meta: { ispublic: true } },
      { path: 'help/:tag', name: 'helptag', component: help, props: true, meta: { ispublic: true } },
      { path: 'helpcontent/:id', name: 'helpcontent', component: helpcontent, props: true, meta: { ispublic: true } },
      { path: 'activity', name: 'activity', component: activity, meta: { ispublic: true } },
      { path: 'activitycontent/:id', name: 'activitycontent', component: activitycontent, props: true, meta: { ispublic: true } },
      { path: 'job', name: 'job', component: job, meta: { ispublic: true } },
      { path: 'jobcontent/:id', name: 'jobcontent', component: jobcontent, props: true, meta: { ispublic: true } },
      { path: 'oldstuff', name: 'oldstuff', component: oldstuff, meta: { ispublic: true } },
      { path: 'oldstuffcontent/:id', name: 'oldstuffcontent', component: oldstuffcontent, props: true, meta: { ispublic: true } },
      { path: 'news', name: 'news', component: news, meta: { ispublic: true } },
      { path: 'newscontent/:id', name: 'newscontent', component: newscontent, props: true, meta: { ispublic: true } },
      { path: 'companycontent/:id', name: 'companycontent', component: companycontent, props: true, meta: { ispublic: true } },
      { path: 'search', name: 'search', component: search, meta: { ispublic: true } },
      { path: 'feedback', name: 'feedback', component: feedback, meta: { ispublic: true } },
      { path: 'report', name: 'report', component: report, meta: { ispublic: true } },
      { path: 'appeal', name: 'appeal', component: appeal, meta: { ispublic: true } },
      {
        path: 'admin',
        component: adminindex,
        children: [
          { path: '', name: 'adminhome', component: adminhome },
          { path: 'myself', name: 'myself', component: myself },
          { path: 'notice', name: 'notice', component: notice },
          { path: 'helplist', name: 'helplist', component: helplist },
          { path: 'createhelp', name: 'createhelp', component: createhelp },
          { path: 'updatehelp/:id', name: 'updatehelp', component: createhelp, props: true },
          { path: 'activitylist', name: 'activitylist', component: activitylist },
          { path: 'createactivity', name: 'createactivity', component: createactivity },
          { path: 'updateactivity/:id', name: 'updateactivity', component: createactivity, props: true },
          { path: 'company', name: 'company', component: company },
          { path: 'oldstufflist', name: 'oldstufflist', component: oldstufflist },
          { path: 'createoldstuff', name: 'createoldstuff', component: createoldstuff },
          { path: 'updateoldstuff/:id', name: 'updateoldstuff', component: createoldstuff, props: true },
          { path: 'newslist', name: 'newslist', component: newslist },
          { path: 'createnews', name: 'createnews', component: createnews },
          { path: 'updatenews/:id', name: 'updatenews', component: createnews, props: true }
        ]
      }
    ]
  }
  /* {路由懒加载
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/!* webpackChunkName: "about" *!/ '../views/About.vue')
  } */
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, Form, next) => {
  // console.log(to)
  if (!to.meta.ispublic && (!sessionStorage.luffy_jwt_token || !sessionStorage.userinfo)) {
    return next('/')
  }
  next()
})

export default router
